﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using DataMap;
using EFRepository;

namespace EFService
{
    public class ServiceBase<TMainRepository,TTableName, TModel> where TMainRepository : class,IRepositoryBase, new()
    {
        #region Properties
        public virtual List<TTableName> Query { get; set; }
        public virtual TMainRepository Main { get; set; }
        public virtual int Count { get; set; }

        #endregion
        #region Constructors
        public ServiceBase()
        {
            Main = new TMainRepository();
        }
        #endregion
        #region Methods

        public virtual List<TModel> GetMainDataSource(int skip, int take, string orderBy, bool asending)
        {
            Main.PrepareParameter(skip, take, asending);
            GetQuery(orderBy);
            GetCount();
            return Query.ToList().Map<TModel, TTableName>().ToList();
        }
        public virtual void GetQuery(string orderBy)
        {

        }
        public virtual void GetCount()
        {
            this.Count = Main.Count;
        }
        #endregion
    }
}
